From b0f432296fe273af86f55450b3e2bdb453f5ed18 Mon Sep 17 00:00:00 2001 From: Johann Tuffe Date: Mon, 13 Jul 2015 13:23:33 +0800 Subject: [PATCH] avoid an unnecessary clone in without_prefix This is a very tiny optimization ... An unnecessary clone was done because of matching on a tuple. Checking items separately avoids it entirely. --- src/cargo/util/paths.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index a758b58c9..7cc7d619e 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -47,20 +47,19 @@ pub fn normalize_path(path: &Path) -> PathBuf { Component::Normal(c) => { ret.push(c); } } } - return ret; + ret } pub fn without_prefix<'a>(a: &'a Path, b: &'a Path) -> Option<&'a Path> { let mut a = a.components(); let mut b = b.components(); loop { - let mut a2 = a.clone(); - match (a2.next(), b.next()) { - (Some(x), Some(y)) if x == y => a = a2, - (Some(_), Some(_)) | - (None, Some(_)) => return None, - (Some(_), None) | - (None, None) => return Some(a.as_path()), + match b.next() { + Some(y) => match a.next() { + Some(x) if x == y => continue, + _ => return None, + }, + None => return Some(a.as_path()), } } } -- 2.30.2